/*Replication file for "A Good Partisan? Ideology, Loyalty, and Public Evaluations of Members of Congress" by Geoff Sheagley, Logan Dancey, and John Henderson. Legislative Studies Quarterly*/

//Do file by Logan Dancey

//Replication file to merge 2019 Member Info with 2019 CES Data*/

*Set working directory
cd ""

*Opening 2019 CES
use "CCES19_Common_OUTPUT.dta", clear


***Produce unique identifier statedist variable for merge***


*Code to produce state abbreviations from state names in inputstate variable label
decode inputstate, gen(statename)

gen stateabb="AL" if statename=="Alabama"
replace stateabb="AK" if statename=="Alaska"
replace stateabb="AZ" if statename=="Arizona"
replace stateabb="AR" if statename=="Arkansas"
replace stateabb="CA" if statename=="California"
replace stateabb="CO" if statename=="Colorado"
replace stateabb="CT" if statename=="Connecticut"
replace stateabb="DE" if statename=="Delaware"
replace stateabb="FL" if statename=="Florida"
replace stateabb="GA" if statename=="Georgia"
replace stateabb="HI" if statename=="Hawaii"
replace stateabb="ID" if statename=="Idaho"
replace stateabb="IL" if statename=="Illinois"
replace stateabb="IN" if statename=="Indiana"
replace stateabb="IA" if statename=="Iowa"
replace stateabb="KS" if statename=="Kansas"
replace stateabb="KY" if statename=="Kentucky"
replace stateabb="LA" if statename=="Louisiana"
replace stateabb="ME" if statename=="Maine"
replace stateabb="MD" if statename=="Maryland"
replace stateabb="MA" if statename=="Massachusetts"
replace stateabb="MI" if statename=="Michigan"
replace stateabb="MN" if statename=="Minnesota"
replace stateabb="MS" if statename=="Mississippi"
replace stateabb="MO" if statename=="Missouri"
replace stateabb="MT" if statename=="Montana"
replace stateabb="NE" if statename=="Nebraska"
replace stateabb="NV" if statename=="Nevada"
replace stateabb="NH" if statename=="New Hampshire"
replace stateabb="NJ" if statename=="New Jersey"
replace stateabb="NM" if statename=="New Mexico"
replace stateabb="NY" if statename=="New York"
replace stateabb="NC" if statename=="North Carolina"
replace stateabb="ND" if statename=="North Dakota"
replace stateabb="OH" if statename=="Ohio"
replace stateabb="OK" if statename=="Oklahoma"
replace stateabb="OR" if statename=="Oregon"
replace stateabb="PA" if statename=="Pennsylvania"
replace stateabb="RI" if statename=="Rhode Island"
replace stateabb="SC" if statename=="South Carolina"
replace stateabb="SD" if statename=="South Dakota"
replace stateabb="TN" if statename=="Tennessee"
replace stateabb="TX" if statename=="Texas"
replace stateabb="UT" if statename=="Utah"
replace stateabb="VT" if statename=="Vermont"
replace stateabb="VA" if statename=="Virginia"
replace stateabb="WA" if statename=="Washington"
replace stateabb="WV" if statename=="West Virginia"
replace stateabb="WI" if statename=="Wisconsin"
replace stateabb="WY" if statename=="Wyoming"
replace stateabb="DC" if statename=="District of Columbia"

*Creating a dash variable
gen dash="-"

*Creating statedist variable
egen statedist=concat(stateabb dash cdid116)
tab statedist


*Merging with Pelosi Vote
merge m:1 statedist using "2019MemberInfo.dta", generate(_mergePelosiVotes) 
//251 not matched from master these members should be missing due to member turnover between vote and CES
tab statedist if _mergePelosiVotes==1
//5 not matched from using
tab statedist if _mergePelosiVotes==2 // Delegates

tab CurrentHouseName if party==100 & oppose_pelosi==1 //Shows names of Democratic members listed as not supporting Pelosi


